package org;

import org.entities.LevelObject;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.Log;
//import org.newdawn.slick.opengl.renderer.Renderer;

public class Weasel extends StateBasedGame {

    public AppGameContainer app; //needed to have fullscreen (F2 key)
    public GameContainer container;
    private static int resolutionX;
    private static int resolutionY;
    /**
     * Create a new test of graphics context rendering
     */
    public Weasel() {
        super("Space Weasel");
    }

    public void initStatesList(GameContainer container) throws SlickException {
        //Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
        if (container instanceof AppGameContainer) {
            app = (AppGameContainer) container;
        }
        addState(new TitleState());
        addState(new CtrlState());
        addState(new GameState());
        addState(new GameOver());
        addState(new Transition());
        addState(new MapState());
        addState(new IntroState());
        addState(new StatusState());
        addState(new InfoState());
    }

    /**
     * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
     */
    public void keyPressed(int key, char c) {
        super.keyPressed(key, c);

        if (key == Input.KEY_F) {
            if (app != null) {
                try {
                    app.setFullscreen(!app.isFullscreen());
                } catch (SlickException e) { Log.error(e);
                }                
                if (!app.isFullscreen()) {
                    app.setMouseGrabbed(false);
                }
                if (app.isFullscreen()) {
                    app.setMouseGrabbed(true);
                }
            }
        }
    }

    /**
     * Entry point to our test
     *
     * @param argv The arguments passed to the test
     */
    public static void main(String[] argv) {
        if (!LevelObject.debugMode){
            resolutionX=800;
            resolutionY=600;
        }
        if (LevelObject.debugMode){
            resolutionX=400;
            resolutionY=300;
        }
        try {
            AppGameContainer container = new AppGameContainer(new Weasel());

            container.setDisplayMode(resolutionX, resolutionY, false);

            container.start();
        } catch (SlickException e) {
            e.printStackTrace();
        }
    }
}